/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.washburn.cm333.project.gui;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.swing.JOptionPane;

import edu.washburn.cm333.project.entities.Main;
import edu.washburn.cm333.project.entities.Property;
import edu.washburn.cm333.project.entities.PropertyManager;
import edu.washburn.cm333.project.entities.Tenant;

/**
 *
 * @author Midwest Health
 */
public class TenantForm extends javax.swing.JFrame {

	public void MakeVisible() {
		this.setVisible(true);
	}

	public void Hide() {
		this.setVisible(false);
	}

	public TenantForm() {
		initComponents();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		btnSubmit = new javax.swing.JButton();
		btnExit = new javax.swing.JButton();
		lblTitle = new javax.swing.JLabel();
		lblFName = new javax.swing.JLabel();
		lblLName = new javax.swing.JLabel();
		lblSSN = new javax.swing.JLabel();
		txtFNamed1 = new javax.swing.JTextField();
		txtLName = new javax.swing.JTextField();
		txtSSN = new javax.swing.JTextField();

		setTitle("New Tenant Form");

		btnSubmit.setText("Submit");
		btnSubmit.setToolTipText("");
		btnSubmit.setDoubleBuffered(true);
		btnSubmit.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnSubmitActionPerformed(evt);
			}
		});

		btnExit.setText("Exit");
		btnExit.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnExitActionPerformed(evt);
			}
		});

		lblTitle.setFont(new java.awt.Font("Tahoma", 1, 18));
		lblTitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		lblTitle.setText("Add New Tenant");

		lblFName.setText("Tenant First Name");

		lblLName.setText("Tenant Last Name");

		lblSSN.setText("Tenant SSN");
		lblSSN.setToolTipText("");

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addComponent(lblTitle,
						javax.swing.GroupLayout.Alignment.TRAILING,
						javax.swing.GroupLayout.DEFAULT_SIZE, 365,
						Short.MAX_VALUE)
				.addGroup(
						layout.createSequentialGroup()
								.addGap(48, 48, 48)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														layout.createSequentialGroup()
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.TRAILING,
																				false)
																				.addComponent(
																						lblLName,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						Short.MAX_VALUE)
																				.addComponent(
																						lblFName,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						Short.MAX_VALUE)
																				.addComponent(
																						lblSSN,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						85,
																						javax.swing.GroupLayout.PREFERRED_SIZE))
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addGroup(
																						layout.createSequentialGroup()
																								.addPreferredGap(
																										javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																								.addComponent(
																										txtFNamed1,
																										javax.swing.GroupLayout.DEFAULT_SIZE,
																										159,
																										Short.MAX_VALUE))
																				.addGroup(
																						layout.createSequentialGroup()
																								.addGap(10,
																										10,
																										10)
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.LEADING)
																												.addComponent(
																														txtSSN,
																														javax.swing.GroupLayout.DEFAULT_SIZE,
																														161,
																														Short.MAX_VALUE)
																												.addComponent(
																														txtLName,
																														javax.swing.GroupLayout.DEFAULT_SIZE,
																														161,
																														Short.MAX_VALUE)))))
												.addGroup(
														layout.createSequentialGroup()
																.addGap(33, 33,
																		33)
																.addComponent(
																		btnSubmit)
																.addGap(65, 65,
																		65)
																.addComponent(
																		btnExit,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		65,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addGap(0,
																		34,
																		Short.MAX_VALUE)))
								.addContainerGap(49, Short.MAX_VALUE)));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						javax.swing.GroupLayout.Alignment.TRAILING,
						layout.createSequentialGroup()
								.addComponent(lblTitle,
										javax.swing.GroupLayout.PREFERRED_SIZE,
										35,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addGap(27, 27, 27)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(lblFName)
												.addComponent(
														txtFNamed1,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGap(18, 18, 18)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(lblLName)
												.addComponent(
														txtLName,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGap(18, 18, 18)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(lblSSN)
												.addComponent(
														txtSSN,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED,
										31, Short.MAX_VALUE)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(btnSubmit)
												.addComponent(btnExit))
								.addGap(39, 39, 39)));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSubmitActionPerformed

		EntityManager em = PropertyManager.getEntityManager();

		em.getTransaction().begin();
		Tenant tenant = new Tenant();
		tenant.setFName(txtFNamed1.getText());
		tenant.setLName(txtLName.getText());
		tenant.setTaxId(txtSSN.getText());
		em.persist(tenant);
		em.getTransaction().commit();

		this.setVisible(false);
	}//GEN-LAST:event_btnSubmitActionPerformed

	private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitActionPerformed
		this.setVisible(false);
	}//GEN-LAST:event_btnExitActionPerformed

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		/* Set the Nimbus look and feel */
		//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
		/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
		 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
		 */
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager
					.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(TenantForm.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(TenantForm.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(TenantForm.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(TenantForm.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		}
		//</editor-fold>

		/* Create and display the form */
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new TenantForm().setVisible(true);
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton btnExit;
	private javax.swing.JButton btnSubmit;
	private javax.swing.JLabel lblFName;
	private javax.swing.JLabel lblLName;
	private javax.swing.JLabel lblSSN;
	private javax.swing.JLabel lblTitle;
	private javax.swing.JTextField txtFNamed1;
	private javax.swing.JTextField txtLName;
	private javax.swing.JTextField txtSSN;
	// End of variables declaration//GEN-END:variables
}
